package com.tgpms.web.permission.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tgpms.common.Result;
import com.tgpms.exception.ExceptionExplain;
import com.tgpms.exception.QueryException;
import com.tgpms.util.Common;
import com.tgpms.util.PageInfo;
import com.tgpms.web.permission.service.PermiService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "PermiController", tags = "权限相关接口")
@RestController
@RequestMapping("/ev/permission")
public class PermiController {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private PermiService permiService;
	
	
	@SuppressWarnings("unchecked")
	@ApiOperation(value = "查询用户安全码信息", notes = "查询用户安全码信息", httpMethod = "POST")
	@PostMapping(value = "/selSecurityItemList")
	public Result selSecurityItemList(@RequestParam(value = "selparam", required = false) String selparam,
			@RequestParam(value = "leftdition", required = false) String leftdition,
			@RequestParam(value = "condition", required = false) String condition,
			@RequestParam(value = "pageNo", required = true) String pageNo,
			@RequestParam(value = "pageSize", required = true) String pageSize) {
		Result result = new Result();
		PageInfo pageInfo = new PageInfo();
		if(Common.isEmpty(pageNo) || Common.isEmpty(pageSize)) {
			result.setSuccess(false);
			result.setMsg(ExceptionExplain.EMPTY_BY_DATA.getExplain());
			return result;
		}
		try {
			pageInfo.setPage(pageNo);
			pageInfo.setSize(pageSize);
			Map<String,String> map = new HashMap<String,String>();
			map.put("selparam", selparam);
			map.put("leftdition", leftdition);
			map.put("condition", condition);
			pageInfo.setQueryMap(map);
			result = permiService.getSecurityItemList(pageInfo);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg(ExceptionExplain.ERROR_BY_QUERY.getExplain());
			throw new QueryException(ExceptionExplain.ERROR_BY_QUERY.getExplain());
		}
		return result;
	}
}
